//
//  HMLoginView.m
//  weibo
//
//  Created by apple on 2016/11/14.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "HMLoginView.h"

@interface HMLoginView ()
@property(strong,nonatomic)UIImageView *circleView;
@property(nonatomic,strong)UIImageView *iv_homeLogin;
@property(nonatomic,strong) UIImageView *iv_back;
@property(nonatomic,strong) UILabel *lb_text;
@property(nonatomic,strong) UIButton *btn_enter;
@property(nonatomic,strong) UIButton *btn_register;
@end


@implementation HMLoginView

-(void)addCircleViewAnimator{
    CABasicAnimation *base = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    base.toValue = @(2*M_PI);
    base.repeatCount = MAXFLOAT;
    base.removedOnCompletion = NO;
    base.duration = 20;
    [_circleView.layer addAnimation:base forKey:nil];
}
-(void)updateHMLoginViewWithText:(NSString *)text imgName:(NSString*)imgName isHomeVc:(BOOL)isHomeVc
{
    self.lb_text.text = text;
    self.circleView.image = [UIImage imageNamed:imgName];
    if (isHomeVc) {
        [self addCircleViewAnimator];
    }else{
        self.iv_back.hidden = YES;
        self.iv_homeLogin.hidden = YES;
    }

}

#pragma mark
#pragma mark - 程序入口
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupUI];
        self.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
    }
    return self;
}
-(void)setupUI{
    #pragma mark 加入父视图
    [self addSubview:self.circleView];
    [self addSubview:self.iv_back];
    [self addSubview:self.iv_homeLogin];
    [self addSubview:self.lb_text];
    [self addSubview:self.btn_enter];
    [self addSubview:self.btn_register];
    
    #pragma mark  添加约束
    [_circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-100);
    }];
    [_iv_back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_circleView);
    }];
    [_iv_homeLogin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_circleView);
    }];
    [_lb_text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_circleView);
        make.top.equalTo(_circleView.mas_bottom).offset(20);
    }];
    [_btn_enter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.mas_centerX).offset(-20);
        make.top.equalTo(_lb_text.mas_bottom).offset(20);
        make.width.equalTo(@80);
        make.height.mas_equalTo(30);
    }];
    [_btn_register mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.mas_centerX).offset(20);
        make.top.equalTo(_lb_text.mas_bottom).offset(20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
    #pragma mark 添加点击事件
    [_btn_enter addTarget:self action:@selector(clickEnterBtn) forControlEvents:UIControlEventTouchUpInside];
    [_btn_register addTarget:self action:@selector(clickRegisterBtn) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark
#pragma mark - 懒加载
-(UIImageView *)circleView{
    if (!_circleView) {
        _circleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
        [_circleView sizeToFit];
    }
    return _circleView;
}
-(UIImageView *)iv_homeLogin{
    if (!_iv_homeLogin) {
        _iv_homeLogin = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
        [_iv_homeLogin sizeToFit];
    }
    return _iv_homeLogin;
}
-(UIImageView *)iv_back{
    if (!_iv_back) {
        _iv_back = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
        [_iv_back sizeToFit];
    }
   return _iv_back;
}
-(UILabel *)lb_text{
    if (!_lb_text) {
        _lb_text = [[UILabel alloc]initWithText:@"关注一些人，回到这里看看有什么惊喜" textColor:[UIColor grayColor] textAlignment:NSTextAlignmentCenter fontSize:14];
        _lb_text.preferredMaxLayoutWidth = 220;
        _lb_text.numberOfLines = 0;
    }
    return _lb_text;
}
-(UIButton *)btn_enter{
    if (!_btn_enter) {
        _btn_enter = [[UIButton alloc]initWithTitle:@"登入" titleColor:[UIColor grayColor] fontSize:14 backeImgName:@"common_button_white"];
    }
    return _btn_enter;
}
-(UIButton *)btn_register{
    if (!_btn_register) {
        
        _btn_register = [[UIButton alloc]initWithTitle:@"注册" titleColor:[UIColor orangeColor]fontSize:14 backeImgName:@"common_button_white"];
    }
    return _btn_register;
}
#pragma mark
#pragma mark - 点击事件
-(void)clickEnterBtn{
    if ([self.delegate respondsToSelector:@selector(clickEnterBtn)]) {
        [self.delegate clickEnterBtn];
    }
}
-(void)clickRegisterBtn{
    if ([self.delegate respondsToSelector:@selector(clickRegisterBtn)]) {
        [self.delegate clickRegisterBtn];
    }
}
@end
